#include <stdio.h>
#include<stdlib.h>
#define InitSize 10
typedef struct{
	int *data;
	int length;
	int MaxSize;
}SqList;
void InitList(SqList *list){//初始化。为传过来的结构体开辟内存空间
	//	printf("%d",list->length);
	list->data = (int *)malloc(sizeof(int) * InitSize);
	if(list->data==NULL)//判断空间是否开辟成功
	{
		printf("malloc fail\n");
		exit(0);
	}
	list->length = 0;
	list->MaxSize = InitSize;
}
void listOutput(SqList *list){
	printf("顺序表的长度为:%d\n",list->length);
	for(int i=0;i<list->length;i++){
		printf("%d\n",list->data[i]);
	}
}
void ListInput(SqList *list){
	printf("请输入你要输入的数字,-1以结束输入!\n");
	int data,i;
	i = 0;
	while(scanf("%d",&data) && data!=-1){
		list->data[list->length++] = data;
	}
	
}
void ListReverse(SqList *list){  //在空间复杂度为O(1)的情况下逆转顺序表
	int front = 0,rear = list->length - 1;
	int temp;
	while(front < rear){
		temp  = list->data[front];
		list->data[front++] = list->data[rear];
		list->data[rear--] = temp;
	}
}
int main(int argc, char *argv[]) {
	SqList *list = (SqList*) malloc(sizeof(SqList));
	InitList(list);
	ListInput(list);
	listOutput(list);
	ListReverse(list);
	
	listOutput(list);
}